package com.Hsu.blog.config;

import com.Hsu.blog.common.Constants;
import com.Hsu.blog.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Hsu琛君珩
 * @ClassName:ErrorAdvice
 * @date 2024-01-24
 * @apiNote
 * @Version: v1.0
 */

@ResponseBody//因为这个返回的是一个对象而不是页面
@ControllerAdvice
public class ErrorAdvice {
    @ExceptionHandler
    public Result errorHandler(Exception e){
        Result result=new Result<>();
        result.setErrorMsg("内部发生错误，请联系管理员");
        result.setCode(Constants.RESULT_FAIL);
        return result;
    }
}
